"""
缓存测试
"""
import time

from django.core.cache import cache
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt

from djco.base.base_api import BaseApi


@csrf_exempt
def set(request):
    cache.set('cache_name', 'cache_value' + str(time.time()), 10000)
    return JsonResponse(BaseApi.api_ajax_success({}, "cache set"))


@csrf_exempt
def delete(request):
    cache.delete('cache_name')
    return JsonResponse(BaseApi.api_ajax_success({}, "cache delete"))


@csrf_exempt
def get(request):
    data = cache.get('cache_name')
    return JsonResponse(BaseApi.api_ajax_success({"data": data}, "cache get"))
